<template>
	<view>
		<navbar title="提交订单" :autoBack="true"></navbar>
		<scroll-view scroll-y="true" class="scbox">
			<view class="con">
				<view class="con__addr" v-if="addr" @click="navto('/pages/addr/list')">
					<image src="/static/goods/addr.png" class="con__addr__icon" mode=""></image>
					<view class="" style="flex: 1;">
						<view class="con__addr__name">
							{{addr.province}}{{addr.city}}{{addr.area}}{{addr.detail}}
						</view>
						<view class="u-flex u-flex-y-center">
							<view class="con__addr__text">
								{{addr.username}}
							</view>
							<view class="con__addr__mobile">
								{{addr.mobile}}
							</view>
						</view>

					</view>
					<image src="/static/goods/m.png" class="con__addr__m" mode=""></image>
				</view>
				<view class="con__addr" v-else @click="navto('/pages/addr/create')">
					<image src="/static/goods/addr.png" class="con__addr__icon" mode=""></image>
					<view class="" style="flex: 1;">
						<view class="con__addr__name" style="margin-bottom: 0;">
							选择收获地址
						</view>
						<!-- <view class="u-flex u-flex-y-center">
								<view class="con__addr__text">
									李甜 
								</view>
								<view class="con__addr__mobile">
									13855670832
								</view>
							</view> -->

					</view>
					<image src="/static/goods/m.png" class="con__addr__m" mode=""></image>
				</view>
				<view class="con__goods">
					<view class="u-flex u-flex-y-center" style="margin-bottom: 28rpx;">
						<image src="/static/goods/sp.png" class="con__goods__icon" mode=""></image>
						<view class="con__goods__title">
							购买商品
						</view>
					</view>
					<view class="u-flex u-flex-y-center">
						<image :src="URL(info.image)" mode="aspectFill" class="con__goods__pic"></image>
						<view class="u-flex u-flex-column u-flex-column u-flex-between" style="height: 196rpx;">
							<view class="">
								<view class="con__goods__name">
									{{info.name}}
								</view>
								<view class="con__goods__num">
									数量:{{num}}
								</view>
							</view>
							<view class="con__goods__price">
								¥ {{info.price}}
							</view>
						</view>
					</view>
				</view>
				<view class="con__fs">
					<view class="con__fs__title">
						服务方式
					</view>
					<view class="u-flex u-flex-y-center u-flex-between" style="margin-top: 42rpx;">
						<view class="u-flex u-flex-y-center con__fs__item" v-for="(item,index) in list" :key="index"
							@click="cur=index,form.sendtype=item.type">
							<view class="con__fs__check">
								<image src="/static/my/check.png" class="con__fs__check__box" v-if="cur==index" mode="">
								</image>
								<image src="/static/my/nocheck.png" class="con__fs__check__box" v-else mode=""></image>

							</view>
							{{item.name}}
						</view>
					</view>
					<view class="con__fs__title" style="margin-bottom: 32rpx;">
						备注
					</view>
					<u--textarea v-model="form.remark" placeholder="请输入备注信息" border='none' count
						maxlength='100'></u--textarea>
				</view>
			</view>
		</scroll-view>
		<view class="footer">
			<view class="footer__l">
				实付款:
			</view>
			<view class="footer__p">
				<text style="font-size: 30rpx;">￥</text>{{info.price*num}}
			</view>
			<u-button color="#3E5170" shape='circle' @click="submit"
				:customStyle='{width:"234rpx",height:"80rpx",margin:"0",padding:0,fontSize:"30rpx",color:"#FFFFFF"}'>提交订单</u-button>
		</view>
	</view>
</template>

<script>
	import goods from '@/api/_goods.js'
	import user from '@/api/_user.js'
	export default {
		data() {
			return {
				value1: '',
				list: [{
						name: '派送',
						type: 1
					},
					{
						name: '自提',
						type: 2
					},
					{
						name: '上门',
						type: 3
					},
					{
						name: '预约上门',
						type: 4
					},
				],
				cur: 0,
				id: '',
				num: 0,
				info: {},
				addr: {},
				form: {
					"goods_id": "",
					"num": "",
					"address_id": "",
					"sendtype": "",
					"remark": ""
				}
			};
		},
		onLoad(o) {
			this.id = o.id
			this.num = o.num
			this.form.num = o.num
			this.form.sendtype =1
			goods.getGoodsDetail({
				id: o.id
			}).then(res => {
				if (res.data.code == 1) {
					this.info = res.data.data
					this.form.goods_id=this.info.id
				}
			})

		},
		methods: {
			submit(){
				goods.ordercreate(this.form).then(res=>{
					if(res.data.code==1){
						uni.$u.toast('提交成功')
						setTimeout(()=>{
							uni.redirectTo({
								url:'/pages/personal/orderlist?type=1'
							})
						},1000)
					}
				})
			}
		},
		onShow() {
			user.defaultAddress().then(res => {
				if (res.data.code == 1) {
					this.addr = res.data.data
					this.form.address_id=this.addr.id
				}
			})
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f0f3f7;
	}

	.scbox {
		height: calc(100vh - var(--status-bar-height) - 44px - 123rpx);
	}

	.con {
		padding: 20rpx 30rpx;

		&__addr {
			height: 141rpx;
			padding: 0 23rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			display: flex;
			align-items: center;
			margin-bottom: 25rpx;

			&__icon {
				width: 36rpx;
				height: 41rpx;
				margin-right: 16rpx;
			}

			&__name {
				font-family: PingFang SC;
				font-weight: 800;
				font-size: 30rpx;
				color: #232323;
				line-height: 30rpx;
				margin-bottom: 20rpx;
			}

			&__text {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #707070;
				line-height: 26rpx;
			}

			&__mobile {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #7F7F7F;
				line-height: 20rpx;
				margin-left: 22rpx;
			}

			&__m {
				width: 9rpx;
				height: 18rpx;
			}
		}

		&__goods {
			padding: 34rpx 0 51rpx 26rpx;
			background-color: #fff;
			margin-bottom: 27rpx;
			border-radius: 20rpx;

			&__icon {
				width: 27rpx;
				height: 28rpx;
				margin-left: 5rpx;
				margin-right: 7rpx;
			}

			&__title {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #3E5170;
				line-height: 24rpx;
			}

			&__pic {
				width: 196rpx;
				height: 196rpx;
				background: #BFCDE0;
				border-radius: 20rpx;
				border: 2rpx solid #FAFAFA;
				margin-right: 16rpx;
			}

			&__name {
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #333333;
				line-height: 30rpx;
				margin-bottom: 22rpx;
			}

			&__num {
				width: fit-content;
				padding: 16rpx 17rpx;
				background: #F7F6F6;
				border-radius: 10rpx;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #3E5170;
				line-height: 24rpx;
			}

			&__price {

				font-family: PingFang SC;
				font-weight: 800;
				font-size: 36rpx;
				color: #FF4E31;
				line-height: 36rpx;
			}
		}

		&__fs {
			padding: 0 30rpx 50rpx;
			background-color: #fff;
			border-radius: 20rpx;

			&__title {
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 26rpx;
				color: #1E1E1E;
				line-height: 26rpx;
				padding-top: 50rpx;
			}

			&__item {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #020202;
				line-height: 26rpx;
			}

			&__check {
				width: 40rpx;
				height: 40rpx;
				border-radius: 50%;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-right: 6rpx;

				&__box {
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
	}

	.footer {
		height: 123rpx;
		background: #FFFFFF;
		position: relative;
		display: flex;
		align-items: center;
		padding: 0 30rpx;

		&__l {
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 25rpx;
			color: #3E5170;
			line-height: 25rpx;

		}

		&__p {
			font-family: DIN Next LT Pro;
			font-weight: 800;
			font-size: 40rpx;
			color: #FF4E31;
			line-height: 33rpx;
			flex: 1;
			margin-top: 6rpx;
		}
	}

	::v-deep.u-textarea {
		padding: 0rpx !important;
	}
</style>